package com.itheima.work;

/**
 * @auther Macrydy
 * @date 2020/7/1 19:20
 */
public class Test7 {
    public static void main(String[] args) {
        int sum = getSum(1, 2, 2);
        System.out.println(sum);

        String s = getString(1, "张三", 123);
        System.out.println(s);
    }

    //定义一个方法,可以完成任意类型,任何个数的数据进行字符串拼接.最后返回拼接后的字符串. 然后在主方法中调用.
    private static String getString(Object...objects) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i <objects.length ; i++) {
            sb.append(objects[i]);
        }
        return sb.toString();
    }

    //定义一个方法,可以求出任意个整数的和.然后再主方法中调用.
    private static int getSum(int...arr) {
        int sum=0;
        for (int i = 0; i <arr.length ; i++) {
            sum+=arr[i];
        }
        return sum;
    }

}
